<?php
require_once('myheader.php');
require_once('myfooter.php');
require_once('helper/connexion.php');
require_once('helper/enseignant_helper.php');
require_once('helper/divers_helper.php');

myHeader('enseignants');
connexion_sql();
$statut=-1;
if(isset($_GET['statut'])){
	$statut = (int) $_GET['statut'];
}
?>
<div class="container">
     <div class="hero-unit pull-left" style="width:500px;height:100px;padding:20px">	  
     	  <h3 class="" style="position:relative;float:left;">Filtres: </h3>
	  <div class="span1" style="position:relative;float:left;">
	       <form class="form-horizontal" style="padding-top:20px;">

		  <label class="control-label" for="selectStatut">Statut:</label>
    		  <div class="controls">
				  <select id="statut" onchange="filterByStatut();">
					  <option value="-1">aucun</option>
				  <?php
					$req = get_all_statut();
					while($row = pg_fetch_assoc($req)){
						echo '<option value="'.$row["id"].'"';
						
						if($statut == $row["id"]) echo "selected";						
						echo '>'.$row["statut"].'</option>';
					 }?>
			    </select> 
      		  
    		  </div>
	       </form>
	  </div>
</div>

<br>
<br>
<br>
<div id="body">
<h2>Enseignants 
<?php if(isset($_SESSION['id']) && $_SESSION['administrateur']) {
		echo '<button class="btn" onclick="window.location=\'gestion_enseignant.php?action=add\';">
				<i class="icon-plus"></i>
			  </button>';
	  }
?>
</h2>
<div id="table_enseignant">
<table class="table table-hover">
<thead><tr>
	<th>Prénom NOM</th>
	<th>Mail</th>
	<th>Statut</th>
	<th>Etablissement</th>
	<th>Service statutaire</th>
	<th>service effectué</th>
<?php if(isset($_SESSION['id']) && $_SESSION['administrateur']) { 
		echo '<th>Actions</th>';
	  }
?>
</tr></thead>
<?php
if($statut == -1){
	$req = getEnseignants();
} else {
	$req = getEnseignantsByStatut($statut);
}
while($row = pg_fetch_assoc($req)){
    echo '<tr>
			<td><a href="detail_enseignant.php?id='.$row['id'].'">'.$row['prenom'].' '.strtoupper($row['nom']).'</a></td>
			<td>'.$row['mail'].'</td>
			<td>'.$row['statut'].'</td>
			<td>'.$row['etablissement'].'</td>
			<td>'.$row['nbhstatut'].'</td>
			<td>'.$row['nbhreel'].'</td>
			';
	
	if(isset($_SESSION['id']) && $_SESSION['administrateur']) {
		echo '<td>
				<a href="gestion_enseignant.php?action=edit&id='.$row['id'].'">
					<i class="icon-pencil"></i>
				</a>
				<a href="#" class="pull-right" onclick="suppr_enseignant('.$row['id'].')">
					<i class="icon-remove"></i>
				</a>
			  </td>';
	}
	echo '</tr>';
}
?>
</table>
</div>
</div>
</div>
<?php
myFooter();
?>
